package cn.dw.mm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.dw.mm.domain.Authority;
import cn.dw.mm.service.AuthorityService;

@Controller
@RequestMapping("/authority")
public class AuthorityController {
	
	@Autowired
	private AuthorityService authorityService;
	
	@RequestMapping("/page")
	public String page() {
		return "authority/list";
	}
	
	@RequestMapping("/add")
	public String add(Authority authority) {
		authorityService.insertSelective(authority);
		return "success";
	}
	
	@RequestMapping("/del")
	public String del(String ids) {
		String[] idList = ids.split(",");
		for (String id : idList) {
			authorityService.deleteByPrimaryKey(Integer.parseInt(id));
		}
		return "success";
	}
	
	@RequestMapping("/query")
	@ResponseBody
	public Authority query(Authority authority) {
		return authorityService.selectByPrimaryKey(authority.getId());
	}
	
	@RequestMapping("/selectAll")
	@ResponseBody
	public List<Authority> selectAll(Authority authority) {
		return authorityService.selectAll(authority);
	}
	
	@RequestMapping("/mod")
	public String mod(Authority authority) {
		authorityService.updateByPrimaryKeySelective(authority);
		return "success";
	}
}
